package com.easy.controller;

import java.util.Map;

import com.easy.entity.Staff;
import com.easy.utils.Sys;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.easy.service.StaffService;

import javax.servlet.http.HttpSession;

@RestController
public class LoginController {
    @Autowired
    StaffService staffService;

    @RequestMapping("/dologin")
    // 登录判断。密码处理等
    public boolean doLogin(@RequestParam Map params, HttpSession session) {

        return staffService.login(params, session);

    }

    @RequestMapping("/islogin")
    //判断是否已经登陆过，防止通过地址栏访问内部数据，与拦截器配合使用
    public Staff isLogin(HttpSession session) {

        Staff obj = (Staff) session.getAttribute("LOGINSTAFF");
        return obj;

    }

    @RequestMapping("/login")
    public Object Login(HttpSession session) {
        //是否是从地址栏直接获取数据,与前端layui弹窗配合使用
        Object nologin = session.getAttribute("nologin");
        return nologin;

    }

    @RequestMapping("/loginout")
    public boolean loginout(HttpSession session) {
        //清除session
        if (session != null) {
            session.invalidate();
        }
        return true;

    }

}
